import 'package:flutter/material.dart';
import 'package:treasure/global.dart';
import 'package:treasure/pages/account/account_page.dart';
import 'package:treasure/pages/cabinet/cabinet_page.dart';
import 'package:treasure/pages/home/home_drawer.dart';
import 'package:treasure/pages/treasure/treasure_page.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key, required this.title});

  final String title;

  @override
  State<HomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<HomePage> {
  int _selectedIndex = 0;

  static const List<Widget> _widgetOptions = <Widget>[
    CabinetPage(),
    TreasurePage(),
    AccountPage(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
          actions: <Widget>[
            //导航栏右侧菜单
            IconButton(icon: const Icon(Icons.share), onPressed: () {}),
          ],
        ),
        drawer: const HomeDrawer(), //抽屉
        body: Center(
          child: _widgetOptions[_selectedIndex],
        ),
        bottomNavigationBar: BottomNavigationBar(
          // 底部导航
          items: const <BottomNavigationBarItem>[
            BottomNavigationBarItem(
                icon: Icon(Icons.home), label: '首页'),
            BottomNavigationBarItem(
                icon: Icon(Icons.business), label: '宝物'),
            BottomNavigationBarItem(
                icon: Icon(Icons.account_box), label: '我的'),
          ],
          currentIndex: _selectedIndex,
          fixedColor: Colors.blue,
          onTap: _onItemTapped,
        ),
        floatingActionButton: FloatingActionButton(
            //悬浮按钮
            onPressed: _onAdd,
            //悬浮按钮
            child: const Icon(Icons.add)));
  }

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  void _onAdd() {}
}
